{extend name='template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}
<div class="wrapper">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-body">
                    <table id="table"
                           data-toggle="table"
                           data-side-pagination="server"
                           data-click-to-select="true"
                           data-single-select="true"
                           data-checkbox="true"
                           data-url="{:url('Admin/role_data')}"
                    >
                        <thead>
                        <tr>
                            <th data-field="name">角色名称</th>
                            <th data-field="state" data-checkbox="true"></th>
                        </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
    <div class="row">
        <div style="text-align: center">
            <button class="btn btn-success" onclick="getIdSelections()">确定分配</button>
            <button class="btn btn-warning" onclick="layer_close()">关闭</button>
            <input type="hidden" id="admin_id" name="admin_id" value="{$admin.id}"/>
            <input type="hidden" id="role_id" name="role_id" value="{$admin.role_id}"/>
        </div>

    </div>

</div>
{/block}
{block name='script_extra'}
<script>
    var add_role_url="{:url('Admin/role_update')}"
</script>
<script>
    $('#table').bootstrapTable({
        'onLoadSuccess':function () {
            var role_id=parseInt($('#role_id').val());
            var json={field:"id", values:[role_id]};
            $('#table').bootstrapTable('checkBy',json)
        }
    })
    function getIdSelections() {
        var role_id=$('#table').bootstrapTable('getSelections')[0].id;
        var admin_id=$('#admin_id').val();
        $.ajax({
            url:add_role_url,
            data:{admin_id:admin_id,role_id:role_id},
            success:function (res) {
                if (res.success == true){
                    layer.msg(res.message, {time: 1000},function () {
                        layer_close();
                        parent.$('#table').bootstrapTable('refresh');
                    });
                }else{
                    layer.alert(res.message);
                }
            }
        })

    }
</script>
{/block}